import requests
import pandas as pd
import time
import json
import warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import random

# 禁用 SSL 警告
warnings.simplefilter('ignore', InsecureRequestWarning)


# 读取Excel文件中的链接
def read_urls_from_excel(file_path):
    df = pd.read_excel(file_path)  # 读取Excel文件
    urls = df['链接'].dropna().tolist()  # 假设链接在"链接"这一列，调整列名根据实际情况
    return urls


# 读取文件中的链接
file_path = "apkpoki历史下载地址.xlsx"
urls = read_urls_from_excel(file_path)

num = 0
for url in urls:
    print('')
    num += 1
    url = "https://transparencyreport.google.com/transparencyreport/api/v3/safebrowsing/status?site=" + url
    # time.sleep(random.randint(1, 3))

    # 发起 GET 请求
    res = requests.get(url, verify=False)

    # 检查响应状态码
    if res.status_code == 200:
        res_str = res.text
        res = res_str.replace(")]}'", '').strip()
        res = json.loads(res)
        print(res[0])
        if True in [i for i in res[0] if isinstance(i, bool) and i == True]:
            print('报警')
            print(url)
            # 如果 i == True, 将 URL 写入 log.txt 文件
            with open("log.txt", "a") as log_file:
                log_file.write(url + "\n")

        print("执行成功第：" + str(num) + "个")
    else:
        print(f"请求失败，状态码：{res.status_code}")

